package edu.uta.cse6339.facetedinterface.read.article.labels;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class UniversityLabeledArticles {

	private static HashMap<String,Set<String>> classifedArticles = new HashMap<String,Set<String>>();
	
	//private static final String UNIVERSITY_LABELED_FILE_NAME="src/edu/uta/cse6339/facetedinterface/resources/classified/universityOutFile.txt";
	private static final String UNIVERSITY_LABELED_FILE_NAME="data/output/universityOutFile.txt";
	
	public static void initialise(){
		classifedArticles= ReadClassfiedArticleLabels.readArticleLabels(UNIVERSITY_LABELED_FILE_NAME);
	}
	
	public static Set<String> getArticlesByUniversities(Set<String> universities){
		Set<String> universityArticles = new HashSet<String>();
		ArrayList<Set<String>> tokenListArticle = new ArrayList<Set<String>>();
		for(String university: universities){ 
			university =university.replaceAll("of","");
			university =university.replaceAll("and","");
			university =university.replaceAll("the","");
			String tokens [] =university.split(" ");
			if(tokens!=null && tokens.length>0){
				for(String collegeToken : tokens){
					Set<String> collegeTokenArticles=classifedArticles.get(collegeToken);
					//System.out.println(collegeToken+" "+collegeTokenArticles);
					if(collegeTokenArticles!=null && collegeTokenArticles.size()>0)
						tokenListArticle.add(collegeTokenArticles);
				}
			}
		}
		if(tokenListArticle!=null && tokenListArticle.size()>0){
			universityArticles.addAll(tokenListArticle.get(0));
			for(Set<String> articleSet : tokenListArticle){
				universityArticles.retainAll(articleSet);
			}
		}
		return universityArticles;
	}
	
	public static void main (String args[]){
		initialise();
		HashSet<String> collegeSet =new HashSet<String>();
		collegeSet.add("Louisiana State Univers");
		System.out.println(getArticlesByUniversities(collegeSet));
	}
	
}
